var page_set = document.getElementById('page_set');
var page_changelog = document.getElementById('page_changelog');
var page_about = document.getElementById('page_about');
var aset = document.getElementById('aset');
var ahistory = document.getElementById('ahistory');
var aabout = document.getElementById('aabout');
var textarea = document.getElementById('textarea');
var textarea_hide = document.getElementById('textarea_hide');
var msg = document.getElementById('msg');

function showPageSet(){
	aset.style.background = 'url(li.png) top right';
	ahistory.style.background = 'none';
	aabout.style.background = 'none';
	page_set.style.display = 'block';
	page_changelog.style.display = 'none';
	page_about.style.display = 'none';
}

showPageSet();

chrome.storage.local.get('keywords', function(result) {
	if(JSON.stringify(result) == '{}'){
		textarea_hide.value = '';
	}else{
		textarea.value = result.keywords;
	}
});

chrome.storage.local.get('keywords_hide', function(result) {
	//console.log(result);
	if(JSON.stringify(result) == '{}'){
		textarea_hide.value = '';
	}else{
		textarea_hide.value = result.keywords_hide;
	}
});

function save(){
	var s = textarea.value;
	chrome.storage.local.set({'keywords': s}, function() {
		console.log('saveKeywordsHighlight("' + s + '")');
	});
	msg.textContent = '已保存：高亮关键字';	
}

function save_hide(){
	var s = textarea_hide.value;
	chrome.storage.local.set({'keywords_hide': s}, function() {
		console.log('saveKeywordsHide("' + s + '")');
	});
	msg.textContent = '已保存：隐藏关键字';	
}

document.getElementById('save').addEventListener('click', function(){ save(); },false);
document.getElementById('save_hide').onclick = function() { save_hide(); }

aset.addEventListener('click', function(){
	showPageSet();
},false);

ahistory.addEventListener('click', function(){
	this.style.background = 'url(li.png) top right';
	aset.style.background = 'none';
	aabout.style.background = 'none';
	page_set.style.display = 'none';
	page_changelog.style.display = 'block';
	page_about.style.display = 'none';
},false);

aabout.addEventListener('click', function(){
	this.style.background = 'url(li.png) top right';
	aset.style.background = 'none';
	ahistory.style.background = 'none';	
	page_set.style.display = 'none';
	page_changelog.style.display = 'none';
	page_about.style.display = 'block';
},false);
